package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.ProductBean;
import com.project.bean.ProductOrder;
import com.project.mapper.IProductMapper;
import com.project.mapper.IProductOrderMapper;
import com.project.service.IProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProductOrderServiceImpl implements IProductOrderService {
      @Autowired
      private IProductOrderMapper productOrderMapper;
      @Autowired
      private IProductMapper productMapper;
      
      @Override
      public void findAll(String orderNum) {
            QueryWrapper<ProductOrder> qw=new QueryWrapper<>();
            qw.eq("orderNum",orderNum);
            List<ProductOrder> list=productOrderMapper.selectList(qw);
            list.forEach(n->{
                  QueryWrapper<ProductBean> qw1=new QueryWrapper<>();
                  qw1.eq("productNum",n.getProductNum());
                  ProductBean productBean=productMapper.selectOne(qw1);
                  productBean.setNum(productBean.getNum()+n.getNum());
                  productMapper.updateById(productBean);
            });
      }
}
